home *** CD-ROM | disk | FTP | other *** search
- # Source Generated with Decompyle++
- # File: in.pyo (Python 2.5)
-
- from weakref import ref, ref as weakref_ref
- import new
-
- def better_ref(method, cb = None, obj = None):
- if obj is None:
- return bound_ref(method, cb)
- else:
- return unbound_ref(obj, method, cb)
-
-
- class bound_ref(object):
-
- def __init__(self, method, cb = None):
- funcinfo = funcinfo
- import util.introspect
- self.object = weakref_ref(method.im_self, cb)
- self.func = weakref_ref(method.im_func)
- self.cls = weakref_ref(method.im_class)
-
-
- def __call__(self):
- obj = self.object()
- if obj is None:
- return None
-
- func = self.func()
- if func is None:
- return None
-
- cls = self.cls()
- if cls is None:
- return None
-
- return new.instancemethod(func, obj, cls)
-
-
-
- class unbound_ref(object):
-
- def __init__(self, obj, method, cb = None):
- self.object = weakref_ref(obj)
- self.func = weakref_ref(method)
- if not hasattr(obj, '_unbound_cbs'):
- obj._unbound_cbs = { }
-
- obj._unbound_cbs[self] = method
-
-
- def __call__(self):
- obj = self.object()
- func = self.func()
- if obj is not None and func is not None:
- return func
-
-
-
- def __repr__(self):
- funcinfo = funcinfo
- import util
- return '<unbound_ref to %s, obj is %r>' % (funcinfo(self.func()), self.object())
-
-
- better_ref_types = (bound_ref, unbound_ref)
-
- class stupidref(ref):
-
- def __getattr__(self, attr):
- return getattr(self(), attr)
-
-
- if __name__ == '__main__':
- import doctest
- doctest.testmod(verbose = True)
-
-